package question1.map;

import jdk.nashorn.api.tree.Tree;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class MapDemo {
    public static void main(String[] args) {
        TreeMap<Student, Integer> tm = new TreeMap<>();
        tm.put(new Student("yy","男",24),1);
        tm.put(new Student("yyds","男",18),2);
        tm.put(new Student("nv","男",33),3);
        //方式1，entrySet
        Set<Map.Entry<Student, Integer>> entries = tm.entrySet();
        for (Map.Entry<Student, Integer> entry : entries) {
            System.out.println(entry.getKey()+"="+entry.getValue());
        }
        System.out.println("--------------");
        //方式2，keySet
        Set<Student> students = tm.keySet();
        for (Student student : students) {
            System.out.println(student+"="+tm.get(student));
        }
        System.out.println("-----------------");
        //方式3，forEach
        tm.forEach((s,i)-> System.out.println(s+"="+i));

    }
}
